//
//  LCDiskSettingVC.m
//  LongChain
//
//  Created by FengZi on 2018/4/9.
//  Copyright © 2018年 FengZi. All rights reserved.
//

#import "LCDiskSettingVC.h"
#import "LCPicChartView.h"
#import "LCUserModel.h"

@interface LCDiskSettingVC ()<UITextFieldDelegate>

@property (weak, nonatomic) IBOutlet UIView *picChartBaseView;

@property (weak, nonatomic) IBOutlet UIBarButtonItem *rightBarButtonItem;

@property (nonatomic, assign) NSInteger totalSpace;
@property (nonatomic, assign) NSInteger usedSpace;
@property (nonatomic, assign) NSInteger unusedSpace;
@property (nonatomic, strong) LCPicChartView *picChartView;
@end

@implementation LCDiskSettingVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.totalSpace = [LCUserModel userModelManager].capacity;
    self.usedSpace = [LCUserModel userModelManager].used_capacity;
    [self picChartViewWithData:@[@(self.totalSpace)]];
    
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(changeStoreForUse) name:UITextFieldTextDidChangeNotification object:nil];
    
    
    LCUserModel *userModel = [LCUserModel userModelManager];
    LCLog(@"%d",userModel.capacity);
    LCLog(@"%d",userModel.used_capacity);
    
    
}

- (void)changeStoreForUse {
    self.rightBarButtonItem.enabled = YES;
}
- (void)picChartViewWithData:(NSArray *)datas {
    
    if (self.picChartView) {
        
        [self.picChartView removeFromSuperview];
    }
    self.picChartView = [[LCPicChartView alloc]initWithFrame:CGRectMake(0, 0, CGRectGetWidth(self.picChartBaseView.frame), CGRectGetHeight(self.picChartBaseView.frame))];
    self.picChartView.backgroundColor = [UIColor whiteColor];
    self.picChartView.datas = datas;
    [self.picChartBaseView addSubview:self.picChartView];


}
//  减少空间
- (IBAction)SubtractionSpace:(id)sender {
    
    self.rightBarButtonItem.enabled = YES;
    if (self.unusedSpace >= self.totalSpace ) {
        self.unusedSpace = self.totalSpace;
    }else{
        self.unusedSpace += 10;
    }
    self.usedSpace = self.totalSpace - self.unusedSpace;
    [self picChartViewWithData:@[@(self.usedSpace),@(self.unusedSpace)]];


}

//  增加空间
- (IBAction)AdditionSpace:(id)sender {
    
    self.rightBarButtonItem.enabled = YES;
    if (self.usedSpace >= self.totalSpace ) {
        self.usedSpace = self.totalSpace;
    }else{
        self.usedSpace += 10;
    }
    self.unusedSpace = self.totalSpace - self.usedSpace;
    [self picChartViewWithData:@[@(self.usedSpace),@(self.unusedSpace)]];

    
}

- (IBAction)saveDiskSettingChange:(id)sender {
    
    NSLog(@"保存设置");
}

- (IBAction)backAction:(id)sender {
    
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
